package metadata.schema;

import represent.type.Type;

public class Field {
	
	// FIXED, OFFSET & LENGTH used by storage
	private boolean fixed;	// whether length is fixed
	private int offset;	// offset in a record
	private int length;	// valid if fixed==true
	
	private int type;
	private boolean autoIncrement;
	private boolean nullable;
	private Type defaultValue;
	
	/**
	 * Constructor invoked by 
	 * @param fixed
	 * @param offset
	 * @param length
	 * @param type
	 */
	public Field(boolean fixed, int offset, int length, int type,
			boolean autoIncrement, boolean nullable, Type defaultValue) {
		this.fixed = fixed;
		this.offset = offset;
		if (fixed)
			this.length = length;
		else
			this.length = -1;
		this.type = type;
		
		this.autoIncrement = autoIncrement;
		this.nullable = nullable;
		this.defaultValue = defaultValue;
	}
	
	public boolean isFixed() { return fixed; }
	public int getOffset() { return offset; }
	public int getLength() { return fixed? length : -1; }
	public int getType() { return type; }
	
	public boolean isAutoIncrement() { return autoIncrement; }
	public boolean isNullable() { return nullable; }
	public Type getDefaultValue() { return defaultValue; }
}
